package com.haiertvbic.tvnow.service;

import android.content.Context;
import android.os.Looper;

import com.haier.tvmidlware.TvEpgMidwareService;
import com.haiertvbic.tvnow.model.ChannelBean;
import com.haiertvbic.tvnow.protocol.CAEProtocol;
import com.haiertvbic.tvnow.util.SLog;

public class SwitchChannel {
	protected static final String TAG = "FavChannel";
	private static int switchCode;

	public static void CAESwitchChannel(final int cid,
			final SwitchChanellCallback switchChanellCallback) {
		new Thread() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				switchCode = CAEProtocol.changeChannel(this, Integer.valueOf(cid), 0);
				int num = Integer.valueOf(cid);
//				num = VDService.getDTVIdWithWholeCountryId(1, (short)num);//请求全国频道id
				SLog.i("switchchannel", switchCode + "");
				if(switchCode == 4004500){
					switchChanellCallback.returnData(1,switchCode,num);
				}else{
					switchChanellCallback.returnData(1,switchCode,-1);
				}
			}
		}.start();

	}

	public static void DTVSwitchChannel(final Context context,final int channelId,final SwitchChanellCallback switchChanellCallback){
		new Thread() {
			@Override
			public void run() {
				try {
					Looper.prepare();
				} catch (Exception e) {
//					e.printStackTrace();
				}
				TvEpgMidwareService  tvservice= new TvEpgMidwareService(context);
				tvservice.dtvProgramSelByChannelNum(channelId);
				switchChanellCallback.returnData(0, 0, channelId);
			}
		}.start();
		
	}
}
